package uplift.project;

import java.util.ArrayList;

import uplift.project.model.Suggestion;
import android.app.ActionBar;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ArrayAdapter; 
import android.widget.AdapterView.OnItemClickListener;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View; 


public class SuggestionListActivity extends ListActivity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.suggestions_list);
		
		ArrayList<Suggestion> suggestions = new ArrayList<Suggestion>();
		suggestions.add(new Suggestion("Buy coffee for a stranger", "See the next person in line at the coffee shop? Offer to pay for their drink.", R.drawable.coffee, 5));
		suggestions.add(new Suggestion("Tell a joke to a stranger", "Find the nearest person and tell them this joke: A magician walks down the street and turns into a grocery store!", R.drawable.tell_a_joke, 5));
		suggestions.add(new Suggestion("Pick up a piece of trash", "Walk down the street or go to a nearby public space. Find any trash? Pick it up and put it in a garbage bin.", R.drawable.pick_up_trash, 4.4));
		suggestions.add(new Suggestion("Give a small gift", "Buy something small like a cookie or flowers. Give them to someone you pass during your day.", R.drawable.small_gift, 4));
		suggestions.add(new Suggestion("Free hugs", "Offer a hug to someone who looks like they're having a hard day.", R.drawable.free_hugs, 3.5));

		/*String[] options = new String[]{"Buy coffee for a stranger", "Tell a joke to a stranger", "Pick up a piece of trash",
				"Give a small gift", "Free hugs"};
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, options);*/
		
		SuggestionAdapter adapter = new SuggestionAdapter(this, android.R.layout.simple_list_item_1, suggestions);

		this.getListView().setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> a, View
					v, int position, long id) {
				Intent i = new Intent(v.getContext(), SuggestionActivity.class);
				Suggestion item = (Suggestion)a.getItemAtPosition(position);
				i.putExtra("name", item.getName());
				i.putExtra("desc", item.getDescription());
				i.putExtra("image", item.getImageRes());
				i.putExtra("rating", item.getRating());
				startActivity(i);
			}
		});

		setListAdapter(adapter);
		
		// set the action bar to have up-navigation enabled
	    ActionBar actionBar = getActionBar();
	    actionBar.setDisplayHomeAsUpEnabled(true);

	}
	

	// handles action item button presses
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if(item.getItemId() == android.R.id.home) {
			// move up the hierarchy

			Intent i = new Intent(getListView().getContext(), UpliftActivity.class);
			i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(i);
		} else if(item.getItemId() == R.id.menu_home) {
			// go to Home screen
			
			Intent i = new Intent(getListView().getContext(), UpliftActivity.class);
			i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(i);
		} else if(item.getItemId() == R.id.menu_my_events) {
			// go to My Events screen
			
			Intent i = new Intent(getListView().getContext(), MyEventsTabActivity.class);
			i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(i);
		}
		return true;
	}
	
	// set up Action Bar
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.action_bar, menu);
	    return true;
	}
}
